/**
 * ***************************************************************************** Copyright (c)
 * 2012-2015 Red Hat, Inc. All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * <p>Contributors: Red Hat, Inc. - initial API and implementation
 * *****************************************************************************
 */
package org.eclipse.che.plugin.java.server.jdt.refactoring;

import java.util.Hashtable;
import org.eclipse.che.plugin.java.server.jdt.testplugin.TestOptions;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType;
import org.eclipse.jdt.internal.ui.JavaPlugin;

public class AbstractRefactoringTestSetup /*extends TestSetup*/ {

  private boolean fWasAutobuild;

  /*public AbstractRefactoringTestSetup(Test test) {
  		super(test);
  	}
  */
  protected void setUp() throws Exception {
    //		super.setUp();
    //		fWasAutobuild= CoreUtility.setAutoBuilding(false);
    //		if (JavaPlugin.getActivePage() != null)
    //			JavaPlugin.getActivePage().close();

    Hashtable options = TestOptions.getDefaultOptions();
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB);
    options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, "0");
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
    options.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, String.valueOf(9999));

    JavaCore.setOptions(options);
    TestOptions.initializeCodeGenerationOptions();
    JavaPlugin.getDefault().getCodeTemplateStore().load();

    StringBuffer comment = new StringBuffer();
    comment.append("/**\n");
    comment.append(" * ${tags}\n");
    comment.append(" */");
    StubUtility.setCodeTemplate(
        CodeTemplateContextType.CONSTRUCTORCOMMENT_ID, comment.toString(), null);
  }

  protected void tearDown() throws Exception {
    //		CoreUtility.setAutoBuilding(fWasAutobuild);
    /*
     * ensure the workbench state gets saved when running with the Automated Testing Framework
     * TODO: remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=71362 is fixed
     */
    /* Not needed for JDT/UI tests right now.
    StackTraceElement[] elements=  new Throwable().getStackTrace();
    for (int i= 0; i < elements.length; i++) {
    	StackTraceElement element= elements[i];
    	if (element.getClassName().equals("org.eclipse.test.EclipseTestRunner")) {
    		PlatformUI.getWorkbench().close();
    		break;
    	}
    }
    */
    //		super.tearDown();
  }
}
